/**
 * PieceMovementHub.java
 * 10/05/2011 20:08:34
 */
package model.mediator;

import java.util.ArrayList;

import model.memento.Movement;

/**
 * @author walber
 * 
 */
public class PieceMovementHub implements HubMediator {

	/**
	 * Broadcast domain
	 */
	private final ArrayList<HubColleague> colleagues;

	public PieceMovementHub() {
		this.colleagues = new ArrayList<HubColleague>();
	}

	/**
	 * @see model.mediator.HubMediator#requestMultiMovement(HubColleague, Movement)
	 */
	@Override
	public void requestMultiMovement(HubColleague source, Movement move) {
		for (HubColleague piece : this.colleagues) {
			if (piece != source) {
				piece.requestMultiMovement(move);
			}
		}
	}

	/**
	 * @see model.mediator.HubMediator#requestSingleMovement(HubColleague, Movement)
	 */
	@Override
	public void requestSingleMovement(HubColleague source, Movement move) {
		for (HubColleague piece : this.colleagues) {
			if (piece != source) {
				piece.requestSingleMovement(move);
			}
		}
	}

	/**
	 * @see model.mediator.HubMediator#refuseMovement(HubColleague, Movement)
	 */
	@Override
	public void refuseMovement(HubColleague source, Movement move) {
		for (HubColleague piece : this.colleagues) {
			if (piece != source) {
				piece.refuseMovement(move);
			}
		}
	}

	/**
	 * @see model.mediator.HubMediator#leavePosition(HubColleague, int, int)
	 */
	@Override
	public void leavePosition(HubColleague source, int col, int row) {
		for (HubColleague piece : this.colleagues) {
			if (piece != source) {
				piece.leavePosition(col, row);
			}
		}
	}

	/**
	 * @see model.mediator.HubMediator#addBroadcastColleague(model.mediator.HubColleague)
	 */
	@Override
	public void addBroadcastColleague(HubColleague colleague) {
		this.colleagues.add(colleague);
	}

	/**
	 * @see model.mediator.HubMediator#removeBroadcastColleague(model.mediator.HubColleague)
	 */
	@Override
	public void removeBroadcastColleague(HubColleague colleague) {
		this.colleagues.remove(colleague);
	}
}
